package com.corpgovernment.supplier.common;

import com.ctrip.corp.obt.generic.utils.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class ReceiptUtil {

    public static int expressSupportedReceipts(List<String> receipts) {
        if (CollectionUtils.isEmpty(receipts)) {
            return 0;
        }
        int e = 0;
        for (String receipt : receipts) {
            switch (receipt) {
                case "100":
	                if ((e & 4) != 4) {
		                e += 4;
	                }
                    break;
                case "010":
	                if ((e & 2) != 2) {
		                e += 2;
	                }
                    break;
                case "001":
	                if ((e & 1) != 1) {
		                e += 1;
	                }
                    break;
            }
        }
        return e;
    }

    public static List<String> getSupportedReceipts(Integer e) {

        List<String> sList = new ArrayList<>();
        if (e == null) {
            return sList;
        }
        if ((e & 1) == 1) {
            sList.add("001");
        }
        if ((e & 2) == 2) {
            sList.add("010");
        }
        if ((e & 4) == 4) {
            sList.add("100");
        }
        return sList;
    }

}
